package com.along.dev.rbac.controller;

import com.along.dev.rbac.dto.RoleDTO;
import com.along.dev.rbac.qo.RoleQO;
import com.along.dev.rbac.service.RoleService;
import com.along.utility.common.response.GeneralResult;
import com.along.utility.common.response.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 * @Author: liujinyi
 * @DateTime: 2025/4/9 16:59
 */
@CrossOrigin
@RestController
@RequestMapping("/rbac/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/find")
    public PageResult<RoleDTO> find(@RequestBody RoleQO roleQO) {
        return PageResult.success(roleService.find(roleQO, roleQO.getPage(), roleQO.getRows()));
    }

    @PostMapping("/save")
    public GeneralResult<RoleDTO> save(@RequestBody RoleDTO roleDTO) {
        roleService.save(roleDTO);
        return GeneralResult.success();
    }

    @PostMapping("/update")
    public GeneralResult<RoleDTO> update(@RequestBody RoleDTO roleDTO) {
        roleService.update(roleDTO);
        return GeneralResult.success();
    }

    @PostMapping("/delete")
    public GeneralResult<RoleDTO> delete(@RequestBody RoleDTO roleDTO) {
        roleService.delete(roleDTO);
        return GeneralResult.success();
    }
}
